#include "zevent/event.hpp"
#include <cstdio>

ZEVT_TYPE(e1);
ZEVT_TYPE(e2, int);
ZEVT_TYPE(e3, int, const char *);

struct S {
  auto operator()() {
    using namespace zevent::sml;
    auto a1 = [] { printf("action1\n"); };
    auto a2 = [](const auto e) {
      auto d = *e;
      printf("action2 %d\n", d);
    };
    auto a3 = [](const auto e) {
      auto [d1, d2] = *e;
      printf("action3 %d:%s\n", d1, d2);
    };
    // clang-format off
    return make_transition_table(
        *"s1"_s + zevt<e2> / a2 = "s2"_s
        ,"s2"_s + zevt<e1> / a1 = "s3"_s
        ,"s3"_s + zevt<e3> / a3 = X
      );
    // clang-format on
  }
};

int main() {
  using namespace zevent::sml;
  auto &s = Sm<S>::Create<5>();
  e1::Publish();
  e2::Publish(2);
  e1::Publish();
  e3::Publish(3, "hello world\n");
  puts("After processing events\n");
  Sm<S>::ProcessEvents();
  printf("Is in state X: %s\n", (1 == s.IsState(X) ? "true" : "false"));

  return 0;
}